package io.gitee.loulan_yxq.owner.json.test;

import io.gitee.loulan_yxq.owner.core.collection.CollTool;
import io.gitee.loulan_yxq.owner.json.base.JsonMap;
import io.gitee.loulan_yxq.owner.json.test.domain.User;
import io.gitee.loulan_yxq.owner.json.test.domain.User2;
import io.gitee.loulan_yxq.owner.json.tool.JSON;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

/*********************************************************
 ** TODO 
 ** <br><br>
 ** Date: Created in 2022/1/19  19:09
 ** @author loulan
 ** @version 0.0.0
 *********************************************************/
public class JsonTest2 {
    private User user;
    private List<User> userList;
    private User2 user2;
    private List<User2> user2List;

    @Before
    public void init () {
        this.user = new User();
        user.setSex("未知");
        user.setName("xxoo");
        user.setAge(10);

        this.userList = CollTool.list();
        for (int i = 0; i < 15; i++) {
            User userTemp = new User();
            userTemp.setSex("未知");
            userTemp.setName("xxoo");
            userTemp.setAge(i + 12);
            this.userList.add(userTemp);
        }

        this.user2 = new User2();
        user2.setSex("未知");
        user2.setName("xxoo");
        user2.setAge(10);
        user2.setList(userList);

        this.user2List = CollTool.list();
        for (int i = 0; i < 15; i++) {
            User2 userTemp = new User2();
            userTemp.setSex("未知");
            userTemp.setName("xxoo");
            userTemp.setAge(i + 12);
            userTemp.setList(userList);
            this.user2List.add(userTemp);
        }
    }

    @Test
    public void test01() {
        String json = JSON.toJson(user2List);
        List<JsonMap> jsonMaps = JSON.parseListJsonMap(json);
        System.out.println(jsonMaps);
    }

    @Test
    public void test02() {
        byte[] bytes = JSON.toJsonBytes(user2List);
        System.out.println(bytes);
        List<JsonMap> jsonMaps = JSON.parseListJsonMap(bytes);
        List<User2> user2List1 = JSON.parseList(bytes, User2.class);
        System.out.println(user2List1);
        System.out.println(jsonMaps);
    }
}
